# Contributor: Łukasz Jendrysik
# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=monit
pkgver=5.33.0
pkgrel=3
pkgdesc="Managing and monitoring on a UNIX system"
url="https://mmonit.com/monit/"
arch="all"
license="AGPL-3.0-or-later WITH OpenSSL-Exception"
makedepends="openssl-dev>3 zlib-dev"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://mmonit.com/monit/dist/monit-$pkgver.tar.gz
	fix-invalid-use-of-vfork.patch
	$pkgname.initd
	$pkgname.confd
	"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--without-pam
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm 755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm 644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname

	install -Dm 644 "$builddir"/monitrc \
		"$pkgdir"/etc/monitrc
	sed -i '/allow @monit/s/^/#/' \
		"$pkgdir"/etc/monitrc
	sed -i '/allow @users readonly/s/^/#/' \
		"$pkgdir"/etc/monitrc

	# monit checks for strict permissions of monitrc at startup
	chmod 600 "$pkgdir"/etc/monitrc
}

sha512sums="
f84edfc03a7386bb712c3d1e1e74801c5deea596f533bd898f342c8435e4b9f4225ec24a4daee11c4d23a5742e9f8a9c666ebaa1ba56f13842ac7214d1d70d4f  monit-5.33.0.tar.gz
549fda6dc92c2630152a29f5bb94d29a59abb06300e55eb93ed729758d73ed7dceaa2e9f491c9d33419920aef24c0360f865753be28af13a11216129529611ae  fix-invalid-use-of-vfork.patch
05475c60ddfbf8690a83b83c4ec238d6c8e2f1b38ee076f323937d48bd447bb3d415302c23223f7fc0783476cedda81200ac6e08aa60512838f91ce359f3aaae  monit.initd
0385a06684bae5f66585b7e1de732d9efcb3d13535e5410da85d0a04151ef0c9d8c28f862176a91e5ba769fca5ebab76e5423a8807709859a87314a513acee2d  monit.confd
"
